package sapling.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import sapling.model.Admin;
import sapling.model.LandMass;
import sapling.model.TreeWell;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;

/**
 * Created by ever on 2016/10/9.
 */

@Transactional
public interface TreeWellDao extends JpaRepository<TreeWell, Long> {

    @Query(value = "SELECT * FROM tree_well WHERE land_mass_id =?1",nativeQuery = true)
    List<TreeWell> getlandMassTreeWell(Long landMass_id);

    @Query(value = "select MAX(serial_number) from tree_well where land_mass_id =?1",nativeQuery = true)
    String maxSerialNumber(Long land_mass_id);

    @Query(value = "SELECT id FROM tree_well WHERE land_mass_id =?1",nativeQuery = true)
    List<Long> landMassTreeWellId(Long landMass_id);

    @Query(value = "SELECT distinct land_mass_id FROM tree_well WHERE use_state =?1",nativeQuery = true)
    List<BigInteger> landMass(int state);

    @Query(value = "select * from tree_well where tree_id=?1",nativeQuery = true)
    TreeWell findbytree(long treeid);

    @Query(value = "select count(*) from tree_well where use_state=?1 and land_mass_id=?2",nativeQuery = true)
    BigDecimal getCountisUse(int usestate,long land_mass_id);

    @Query(value = "select count(*) from tree_well where land_mass_id=?1",nativeQuery = true)
    BigDecimal getCountlandmass(long land_mass_id);


}
